import Vue from "vue";
import {request} from "../../../util/request.js";
import dialog from "../../../util/dialog.js";
import VModal from 'vue-js-modal';
Vue.use(VModal,{dialog:true});
import "../../../style/basic.less";
import "./person.less";
let lister_check_list_timer = null;
new Vue({
    el:"#louie",
    data:{
        navs:[
            {name:"可发红包人员",value:"1",icon:"iconfont icon-renyuan"},
            {name:"待审核",value:"0",icon:"iconfont icon-shenhe"}
        ],
        nav_index:0,
        list:[],   //列表
        check_list:[],  //审核列表
        qrcode:""
    },
    created:function(){
         this.getList(1);
         this.getQrcode();
    },
    methods:{
        changeNav(index){
            if(index === this.nav_index) return;
            this.nav_index = index;
            if(index === 1){
                lister_check_list_timer = setInterval(()=>{
                    this.getList(0);
                },500);
            }else{
                clearInterval(lister_check_list_timer);
            }
            this.getList(this.navs[this.nav_index].value);
        },
        /**
         * 获取列表
         */
        getList(status){
            request("personPublish/publishList",{
                status
            })
                .then((res)=>{
                    if(res.data.status === "success"){
                        if(parseInt(status) === 1){
                            this.list = res.data.data;
                        }else{
                            this.check_list = res.data.data;
                        }
                    }else{
                        if(parseInt(status) === 1){
                            this.list = [];
                        }else{
                            this.check_list = [];
                        }
                    }
                });
        },
        /**
         * 获取申请发包人员二维码
         */
        getQrcode(){
            request("personPublish/getApplyQrcode")
                .then((res)=>{
                    if(res.data.status === "success"){
                        this.qrcode = res.data.data;
                    }
                });
        },
        /**
         * 点击dl
         */
        clickDl(person_id){
            let buttons = [
                {
                    title: '删除',
                    default: true,
                    handler: () => {
                        this.changeStatus(person_id,9);
                        this.$modal.hide('dialog');
                    }
                },
                {
                    title: '关闭'
                }
            ];
            if(this.navs[this.nav_index].value === '0'){
                buttons.unshift({
                    title: '审核',
                    handler: () => {
                        this.changeStatus(person_id,1);
                        this.$modal.hide('dialog');
                    }
                });
            }
            this.$modal.show('dialog', {
                text: '操作提示',
                buttons:buttons
            })
        },
        /**
         * 改变状态
         */
        changeStatus(person_id,status){
            request("personPublish/changeStatus",{
                person_id,
                status
            })
                .then((res)=>{
                    if(res.data.status === "success"){
                        this.getList(this.navs[this.nav_index].value);
                    }else{
                        dialog.alert(this,"操作失败");
                    }
                });
        }
    }
});